package com.pda.xinma.presenter;

import com.pda.xinma.bean.LatheMachinBean;
import com.pda.xinma.bean.SelectBean;
import com.pda.xinma.bean.UserBean;
import com.pda.xinma.bean.request.CallCarryRequest;
import com.pda.xinma.contract.CallMaterialContract;
import com.pda.xinma.net.NetUtils;
import com.wangshen.base.net.bean.BaseAppEntity;
import com.wangshen.base.ui.mvp.base.presenter.BasePresenter;

import java.util.List;

import io.reactivex.functions.Consumer;

public class CallMaterialPresenter extends BasePresenter<CallMaterialContract.View> implements CallMaterialContract.Presenter{
    @Override
    public void getLatheListByCenter(String centerCode) {
        NetUtils.geApi().getLatheListByCenter(centerCode)
                .compose(this.handleEverythingResult())
                .subscribe(new Consumer<BaseAppEntity<List<LatheMachinBean>>>() {
                    @Override
                    public void accept(BaseAppEntity<List<LatheMachinBean>> listBaseAppEntity) throws Exception {
                        getView().setLatheList(listBaseAppEntity.getData());
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        getView().showMessage(throwable.getMessage());
                    }
                });
    }

    @Override
    public void callCarry(CallCarryRequest request) {
        NetUtils.geApi().callCarry(request)
                .compose(this.handleEverythingResult())
                .subscribe(new Consumer<BaseAppEntity<UserBean>>() {
                    @Override
                    public void accept(BaseAppEntity<UserBean> listBaseAppEntity) throws Exception {
                        getView().showMessage(listBaseAppEntity.getMessage());
                        getView().finishActivity();
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        getView().showMessage(throwable.getMessage());
                    }
                });
    }

    @Override
    public void popUpWindow(CallCarryRequest request) {
        NetUtils.geApi().popUpWindow(request)
                .compose(this.handleEverythingResult())
                .subscribe(new Consumer<BaseAppEntity<UserBean>>() {
                    @Override
                    public void accept(BaseAppEntity<UserBean> listBaseAppEntity) throws Exception {
                        getView().setPopMsg(listBaseAppEntity.getMessage());
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        getView().showMessage(throwable.getMessage());
                    }
                });
    }
}
